package utility;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class NetworkUtility {
	
	public static InetAddress getLocalIp() throws UnknownHostException {
		String hostName     = InetAddress.getLocalHost().getHostName();
		InetAddress addrs[] = InetAddress.getAllByName(hostName);
		
		for (InetAddress addr: addrs) {
			if (!addr.isLoopbackAddress()) {
				return addr;
			}
		}
		
		return null;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			System.out.println(NetworkUtility.getLocalIp().getHostAddress());
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
